import 'package:allcam/page/car_page.dart';
import 'package:allcam/page/catrgory_page.dart';
import 'package:allcam/page/home_page.dart';
import 'package:allcam/page/member_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class IndexPage extends StatefulWidget {
  const IndexPage({Key? key}) : super(key: key);

  @override
  _IndexPageState createState() => _IndexPageState();
}

class _IndexPageState extends State<IndexPage> {
  int currentIndex = 0;
  var currentPage;

  final tabBodies = [
    HomePage(),
    CateGoryPage(),
    CarPage(),
    MemberPage(),
  ];
  final List<BottomNavigationBarItem> bottomTabs = [
    BottomNavigationBarItem(icon: Icon(Icons.home), title: Text('首页')),
    BottomNavigationBarItem(icon: Icon(Icons.search), title: Text('分类')),
    BottomNavigationBarItem(icon: Icon(Icons.shop), title: Text('购物车')),
    BottomNavigationBarItem(icon: Icon(Icons.person_off), title: Text('会员中心'))
  ];

  @override
  void initState() {
    currentPage = tabBodies[currentIndex];
    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Color.fromRGBO(244, 245, 245, 1.0),
      bottomNavigationBar: BottomNavigationBar(
        type: BottomNavigationBarType.fixed,
        currentIndex: this.currentIndex,
        items: bottomTabs,
        onTap: (index) {
          setState(() {
            this.currentIndex = index;
            currentPage = tabBodies[currentIndex];
          });
        },
      ),
      appBar: AppBar(
        title: Text('百姓生活+'),
      ),
      body: currentPage,
    );
  }
}
